# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)
# 项目信息
project (pyfree-gather)
#
if(WIN32)
    message(STATUS "windows compiling...")
    add_definitions(-D_PLATFORM_IS_WINDOWS_)
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcrtd.lib")
    # SET(CMAKE_BUILD_TYPE "Debug")
    set(ACL_HAS_POLL false)
    set(WIN_OS true)

else(WIN32)
    message(STATUS "linux compiling...")
    add_definitions( -D_PLATFORM_IS_LINUX_)
    set(UNIX_OS true)
    
endif(WIN32)

#输出到demo配置目录
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../demo-project/gather)

# 指定源文件的目录,并将名称保存到变量
SET(source_h
    #
    ${PROJECT_SOURCE_DIR}/../common/pfunc.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_code.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_format.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_str.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_ip.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_time.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_print.h
    #
    ${PROJECT_SOURCE_DIR}/../common/License.h
    ${PROJECT_SOURCE_DIR}/../common/ostype.h
    ${PROJECT_SOURCE_DIR}/../common/version.h
    ${PROJECT_SOURCE_DIR}/../common/Log.h
    ${PROJECT_SOURCE_DIR}/../common/Mutex.h
    ${PROJECT_SOURCE_DIR}/../common/queuedata.h
    ${PROJECT_SOURCE_DIR}/../common/queuedata_single.h
    ${PROJECT_SOURCE_DIR}/../common/DiskSpace.h
    ${PROJECT_SOURCE_DIR}/../common/spaceMgr.h
    ${PROJECT_SOURCE_DIR}/../common/strchange.h
    ${PROJECT_SOURCE_DIR}/../common/File.h
    ${PROJECT_SOURCE_DIR}/../common/appexitio.h
    #
    ${PROJECT_SOURCE_DIR}/channel-conf/conf_app.h
    ${PROJECT_SOURCE_DIR}/channel-conf/conf_channel.h
    ${PROJECT_SOURCE_DIR}/channel-conf/conf_pmap.h
    ${PROJECT_SOURCE_DIR}/channel-conf/dtypedef.h
    ${PROJECT_SOURCE_DIR}/channel-conf/conf_read.h
    ${PROJECT_SOURCE_DIR}/channel-conf/hashmap.h
    ${PROJECT_SOURCE_DIR}/channel-conf/business_def.h
    ${PROJECT_SOURCE_DIR}/channel-conf/gchannel.h
    ${PROJECT_SOURCE_DIR}/channel-conf/tchannel.h
    #
    ${PROJECT_SOURCE_DIR}/lua/luadisp.h
    #
    ${PROJECT_SOURCE_DIR}/net-gather/netgchannel.h
    ${PROJECT_SOURCE_DIR}/net-gather/nettchannel.h
    ${PROJECT_SOURCE_DIR}/net-gather/socketclient.h
    #
    ${PROJECT_SOURCE_DIR}/net-gather/socket_private_acl.h
    ${PROJECT_SOURCE_DIR}/net-gather/socket_service.h
    ${PROJECT_SOURCE_DIR}/net-gather/socket_gather_read.h
    ${PROJECT_SOURCE_DIR}/net-gather/socket_gather_write.h
    ${PROJECT_SOURCE_DIR}/net-gather/socket_gather.h
    #
    ${PROJECT_SOURCE_DIR}/serial-gather/gsmmsg.h
    ${PROJECT_SOURCE_DIR}/serial-gather/serialgchannel.h
    #
    ${PROJECT_SOURCE_DIR}/src/appinfo.h
    ${PROJECT_SOURCE_DIR}/src/gathermgr.h
  )
  
SET(source_cpp
    #
    ${PROJECT_SOURCE_DIR}/../common/pfunc.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_code.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_format.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_str.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_ip.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_time.cpp
    #
    ${PROJECT_SOURCE_DIR}/../common/License.cpp
    ${PROJECT_SOURCE_DIR}/../common/version.cpp
    ${PROJECT_SOURCE_DIR}/../common/Log.cpp
    ${PROJECT_SOURCE_DIR}/../common/Mutex.cpp
    ${PROJECT_SOURCE_DIR}/../common/DiskSpace.cpp
    ${PROJECT_SOURCE_DIR}/../common/spaceMgr.cpp
    ${PROJECT_SOURCE_DIR}/../common/strchange.cpp
    ${PROJECT_SOURCE_DIR}/../common/File.cpp
    ${PROJECT_SOURCE_DIR}/../common/appexitio.cpp
    #
    ${PROJECT_SOURCE_DIR}/channel-conf/conf_read.cpp
    ${PROJECT_SOURCE_DIR}/channel-conf/hashmap.cpp
    ${PROJECT_SOURCE_DIR}/channel-conf/business_def.cpp
    ${PROJECT_SOURCE_DIR}/channel-conf/gchannel.cpp
    ${PROJECT_SOURCE_DIR}/channel-conf/tchannel.cpp
    #
    ${PROJECT_SOURCE_DIR}/lua/luadisp.cpp
    #
    ${PROJECT_SOURCE_DIR}/net-gather/netgchannel.cpp
    ${PROJECT_SOURCE_DIR}/net-gather/nettchannel.cpp
    ${PROJECT_SOURCE_DIR}/net-gather/socketclient.cpp
    #
    ${PROJECT_SOURCE_DIR}/net-gather/socket_private_acl.cpp
    ${PROJECT_SOURCE_DIR}/net-gather/socket_service.cpp
    ${PROJECT_SOURCE_DIR}/net-gather/socket_gather_read.cpp
    ${PROJECT_SOURCE_DIR}/net-gather/socket_gather_write.cpp
    ${PROJECT_SOURCE_DIR}/net-gather/socket_gather.cpp
    #
    ${PROJECT_SOURCE_DIR}/serial-gather/gsmmsg.cpp
    ${PROJECT_SOURCE_DIR}/serial-gather/serialgchannel.cpp
    #
    ${PROJECT_SOURCE_DIR}/src/gathermgr.cpp
	  ${PROJECT_SOURCE_DIR}/src/main.cpp
  )
  
#头文件目录
include_directories(${PROJECT_SOURCE_DIR}/../common)
include_directories(${PROJECT_SOURCE_DIR}/../lua/include)
include_directories(${PROJECT_SOURCE_DIR}/../muparser/include)
include_directories(${PROJECT_SOURCE_DIR}/../libctb/include)
include_directories(${PROJECT_SOURCE_DIR}/channel-conf)
include_directories(${PROJECT_SOURCE_DIR}/lua)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/net-gather)
include_directories(${PROJECT_SOURCE_DIR}/serial-gather)
#
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_acl/include)
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_acl_cpp/include)
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_protocol/include)

if (${WIN_OS})

include_directories(${PROJECT_SOURCE_DIR}/../svc_common)

SET(source_cpp_win
  ${PROJECT_SOURCE_DIR}/../svc_common/WinSVC.cpp
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")

add_definitions(
  "-D_CRT_SECURE_NO_WARNINGS"
  "-D_WINSOCK_DEPRECATED_NO_WARNINGS"
  "-DNO_WARN_MBCS_MFC_DEPRECATION"
  "-DWIN32_LEAN_AND_MEAN"
  # "-D_WIN64"
)

link_directories(
  "${PROJECT_SOURCE_DIR}/../acl-master/dist/lib/win64"
  "${PROJECT_SOURCE_DIR}/../lua/lib64"
  "${PROJECT_SOURCE_DIR}/../muparser/lib"
  "${PROJECT_SOURCE_DIR}/../libctb/lib64"
  )

if (CMAKE_BUILD_TYPE STREQUAL "Debug")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../demo-project/gather)
# 指定生成目标
add_executable(pyfree-gatherd ${source_h} ${source_cpp} ${source_cpp_win})
#acl的debug程序库请自行用源码编译
target_link_libraries(pyfree-gatherd
  nafxcwd.lib
  # LIBCMTD.lib
  Ws2_32.lib
  lib_acl_vc2015d.lib lib_acl_cpp_vc2015d.lib lib_protocol_vc2015d.lib
  luaLibd.lib
  muParserd.lib
  libctbd.lib
)
#拷贝生成文件到下级采集demo配置目录下,第一次编译时请注释,否则cmake命令会异常
# configure_file(${EXECUTABLE_OUTPUT_PATH}/pyfree-gatherd.exe ${EXECUTABLE_OUTPUT_PATH}/../bgather/pyfree-gather COPYONLY)

else(CMAKE_BUILD_TYPE)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../demo-project/gather)
# 指定生成目标
add_executable(pyfree-gather ${source_h} ${source_cpp}  ${source_cpp_win})

target_link_libraries(pyfree-gather
  nafxcw.lib
  # LIBCMT.lib
  # ws2_32.lib
  lib_acl_vc2015.lib lib_acl_cpp_vc2015.lib lib_protocol_vc2015.lib
  luaLib.lib
  muParser.lib
  libctb.lib
)
#拷贝生成文件到下级采集demo配置目录下,第一次编译时请注释,否则cmake命令会异常
# configure_file(${EXECUTABLE_OUTPUT_PATH}/pyfree-gather.exe ${EXECUTABLE_OUTPUT_PATH}/../bgather/pyfree-gather COPYONLY)

endif (CMAKE_BUILD_TYPE)

endif()

if (${UNIX_OS})

execute_process(COMMAND /bin/bash ../build.sh)

add_definitions(
  "-O2"
  "-Wno-invalid-source-encoding"
  "-W"
  "-fPIC"
  "-Wall"
  "-Werror"
  "-Wshadow"
  "-Wformat"
  "-Wpointer-arith"
  "-D_REENTRANT"
  "-D_USE_FAST_MACRO"
  "-Wno-long-long"
  "-Wuninitialized"
  "-D_POSIX_PTHREAD_SEMANTICS"
  "-DACL_PREPARE_COMPILE"
  "-Wno-unused-parameter"
  "-fexceptions"
  )

link_directories(
  "${PROJECT_SOURCE_DIR}/../acl-master"
  "${PROJECT_SOURCE_DIR}/../lua/lib"
  "${PROJECT_SOURCE_DIR}/../muparser/lib"
  "${PROJECT_SOURCE_DIR}/../libctb/lib"
)

# 指定生成目标
add_executable(pyfree-gather ${source_h} ${source_cpp})
#link
target_link_libraries(pyfree-gather 
  -Wl,--allow-multiple-definition
  -lpthread -pthread -lz -lrt -ldl
  libacl_all.a 
  liblua_447.a 
  libmuParser.a
  libctb-0.16.a
)
#拷贝生成文件到下级采集demo配置目录下,第一次编译时请注释,否则cmake命令会异常
configure_file(${EXECUTABLE_OUTPUT_PATH}/pyfree-gather ${EXECUTABLE_OUTPUT_PATH}/../bgather/pyfree-gather COPYONLY)

endif()
